package com.anti.activiti.example;

import com.google.common.base.Objects;
import org.activiti.engine.delegate.BpmnError;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.Expression;
import org.activiti.engine.delegate.JavaDelegate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;

/**
 * @Author: anTi
 * @Date: 2019/3/18 15:33
 * @Description:服务任务实现JavaDelegate
 * @version: 1.0
 */
public class MyPayJavaDelegate implements JavaDelegate, Serializable {
    private static final Logger LOGGER = LoggerFactory.getLogger(MyPayJavaDelegate.class);



    /**
     * 实现JavaDelegate  任务会直接执行不会等待
     * @param delegateExecution
     */
    @Override
    public void execute(DelegateExecution delegateExecution) {
        LOGGER.info("getVariables {}",delegateExecution.getVariables());
        LOGGER.info("run my MyPayJavaDelegate {}",this);

        Object errorflag = delegateExecution.getVariable("errorflag");
        delegateExecution.getParent().setVariableLocal("key2","VALUE2");

        //子流程设置变量
        delegateExecution.setVariable("key1","value1");
        delegateExecution.setVariable("key3","value3");
        //触发边界事件
        if (Objects.equal(errorflag,true)){
            //errorCode 要与流程文件里边的一致
            throw  new BpmnError("bpmnError");
        }
    }
}
